﻿namespace ufida.u9.ait.openapi
{
	using System;
	using System.Collections.Generic;
	using System.Text;
    using ufida.u9.ait.openapi.utils;
    using UFIDA.U9.CBO.Pub.Controller;
    using UFIDA.U9.InvDoc.TransferIn;
    using UFIDA.U9.ISV.TransferInISV.Proxy;
    using UFSoft.UBF.AopFrame;	
	using UFSoft.UBF.Util.Context;

	/// <summary>
	/// TransferInDeleteSV partial 
	/// </summary>	
	public partial class TransferInDeleteSV 
	{	
		internal BaseStrategy Select()
		{
			return new TransferInDeleteSVImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class TransferInDeleteSVImpementStrategy : BaseStrategy
	{
		public TransferInDeleteSVImpementStrategy() { }

		public override object Do(object obj)
		{						
			TransferInDeleteSV bpObj = (TransferInDeleteSV)obj;

			try
			{
				if (bpObj.Data == null || bpObj.Data.Count == 0)
					throw new Exception("传入参数为空");
				List<CommonArchiveDataDTOData> retlist = new List<CommonArchiveDataDTOData>();

				List<object> inputdtos = DTOUtils.DTOListPropCopy(bpObj.Data.ConvertAll(item => item as object)
					, typeof(CommonArchiveDataDTOData));
				foreach (CommonArchiveDataDTOData dto in inputdtos)
				{
					TransferIn item = TransferIn.Finder.Find($"DocNo='{dto.Code}'");
					if (item == null)
					{
						//新增逻辑
						throw new Exception($"单号:{dto.Code}不存在,不能删除!");
					}
					else
					{
						//修改逻辑
						CommonDeleteTransferInSVProxy proxy = new CommonDeleteTransferInSVProxy();
						proxy.BeDelTransferInDocInfoList=new List<CommonArchiveDataDTOData> {dto};
						proxy.Do();

						dto.ID = item.ID;
						dto.Name = item.DocType.Name;
						retlist.Add(dto);
					}
				}
				return ResultUtils.success(bpObj, bpObj.Data, retlist);
			}
			catch (Exception ex)
			{
				return ResultUtils.error(bpObj, bpObj.Data, ex);
			}
		}		
	}

	#endregion
	
	
}